package com.tencent.org.service.impl;

import com.tencent.basic.util.PageList;
import com.tencent.org.domain.Type;
import com.tencent.org.mapper.TypeMapper;
import com.tencent.org.query.TypeQuery;
import com.tencent.org.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class TypeServiceImpl implements TypeService {
    // 注入DepartmentMapper对象
    @Autowired
    private TypeMapper typeMapper;

    @Override
    @Transactional
    public void del(Long id) {
        typeMapper.del(id);
    }

    @Override
    @Transactional
    public void add(Type type) {
        typeMapper.add(type);
    }

    @Override
    @Transactional
    public void update(Type type) {
        typeMapper.update(type);
    }

    @Override
    public List<Type> findAll() {
        return typeMapper.findAll();
    }

    @Override
    public Type findById(Long id) {
        return typeMapper.findById(id);
    }

    @Override
    public PageList<Type> queryPage(TypeQuery typeQuery) {
        // 查询数据的总条数
        Integer totals = typeMapper.queryCount(typeQuery);
        if (totals == 0){
            return new PageList<>();
        }
        // 查询当前页的数据
        List<Type> data = typeMapper.queryData(typeQuery);
        return new PageList<>(data, totals);

    }

    @Override
    public void patchDel(List<Long> ids) {
        typeMapper.patchDel(ids);
    }
}
